<template>
  <div class="search">
    <div class="header">
      <input
        type="text"
        @keyup.enter="Search"
        v-model="key"
      />
      <img src="../../../assets/images/icon/search.png" alt="" />
    </div>

    <div class="listContent">
      <div class="item" v-for="item of movies" :key="item._id">
        <img :src="item.pic" alt="" @click="goDetail(item._id)" />
        <p>{{ item.title }}</p>
        <div>
          <span>{{ item.rating }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      key: "",
      movies: [],
    };
  },
  methods: {
    Search() {
      this.$http(
        `http://122.112.161.135:4000/api/search?keyword=${this.key}`
      ).then((res) => {
        this.movies = res.data.res;
      });
    },
    goDetail(id){
        this.$router.push(`/movie/detail/${id}`)
    }
  },
};
</script>

<style scoped>
.header {
  height: 1rem;
  position: relative;
}
.header input {
  width: 100%;
  height: 100%;
  background-color: #f2f2f2;
  outline: none;
  border: none;
  padding-left: 1.5rem;
  box-sizing: border-box;
}
.header img {
  width: 0.5rem;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 0.3rem;
}


.listContent {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 0.3rem
}
.listContent .item {
  width: 2.8rem;
}
.listContent .item img {
  width: 100%;
  height: 4rem;
  margin-bottom: 0.2rem;
}
</style>